package cn.bravolinks.tools.utils;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by yanqin on 2017/6/4.
 */
public class CommonUtil {

    /**
     *
     * 加密需要调用的方法
     * @param b
     * @return String
     */
    public static String base64Encode(byte[] b){
        if(b == null){
            return null;
        }
        return new BASE64Encoder().encode(b);
    }

    /**
     *
     * 进行加密
     * @param str
     * @return String
     */
    public static String md5Base64(String str){
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            return base64Encode(md5.digest(str.getBytes()));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

}
